package com.example.auv_660.auvorderload;

import com.example.auv_660.MainActivity;
import com.example.auv_660.command.AUVPropeller;
import com.example.auv_660.util.Constants;
import com.example.auv_660.util.MsgType;

public class HardwareSelfTestOrderLoad extends OrderLoad {
    private int threadPropellerKey;
    private int threadLightKey;
    private MainActivity mainActivity = MainActivity.getInstance();

    @Override
    public void doOrder(String order) {
        if (order.contains(Constants.CHECK_AUV_MODEL_HARDWARE_SELF_TEST_ORDER))
        {
            mainActivity.sendMsgToMainThread(MsgType.CONTROLLER_MSG, "自检中");

            String AUVorder = Constants.AUV_PROPELLER_ORDER_PREFIX + Constants.AUV_SELF_TEST_PROPELLER_ORDER_I
                    + Constants.AUV_ORDER_SUFFIX;

            AUVPropeller.INSTANCE.getAuvPropellerCommand().writeCommand(AUVorder);

            AUVorder = Constants.AUV_PROPELLER_ORDER_PREFIX + Constants.AUV_SELF_TEST_PROPELLER_ORDER_II
                    + Constants.AUV_ORDER_SUFFIX;
            AUVPropeller.INSTANCE.getAuvPropellerCommand().writeCommand(AUVorder);

            AUVorder = Constants.AUV_PROPELLER_ORDER_PREFIX + Constants.AUV_SELF_TEST_PROPELLER_ORDER_III
                    + Constants.AUV_ORDER_SUFFIX;
            AUVPropeller.INSTANCE.getAuvPropellerCommand().writeCommand(AUVorder);

            AUVorder = Constants.AUV_PROPELLER_ORDER_PREFIX + Constants.AUV_SELF_TEST_PROPELLER_ORDER_I
                    + Constants.AUV_ORDER_SUFFIX;
            AUVPropeller.INSTANCE.getAuvPropellerCommand().writeCommand(AUVorder);

            AUVorder = Constants.AUV_PROPELLER_ORDER_PREFIX + Constants.AUV_SELF_TEST_PROPELLER_ORDER_II
                    + Constants.AUV_ORDER_SUFFIX;
            AUVPropeller.INSTANCE.getAuvPropellerCommand().writeCommand(AUVorder);

            AUVorder = Constants.AUV_PROPELLER_ORDER_PREFIX + Constants.AUV_SELF_TEST_PROPELLER_ORDER_III
                    + Constants.AUV_ORDER_SUFFIX;
            AUVPropeller.INSTANCE.getAuvPropellerCommand().writeCommand(AUVorder);

            AUVorder = Constants.AUV_PROPELLER_ORDER_PREFIX + Constants.AUV_SELF_TEST_PROPELLER_ORDER_I
                    + Constants.AUV_ORDER_SUFFIX;
            AUVPropeller.INSTANCE.getAuvPropellerCommand().writeCommand(AUVorder);

            AUVorder = Constants.AUV_PROPELLER_ORDER_PREFIX + Constants.AUV_SELF_TEST_PROPELLER_ORDER_II
                    + Constants.AUV_ORDER_SUFFIX;
            AUVPropeller.INSTANCE.getAuvPropellerCommand().writeCommand(AUVorder);

            AUVorder = Constants.AUV_PROPELLER_ORDER_PREFIX + Constants.AUV_SELF_TEST_PROPELLER_ORDER_III
                    + Constants.AUV_ORDER_SUFFIX;
            AUVPropeller.INSTANCE.getAuvPropellerCommand().writeCommand(AUVorder);

            mainActivity.sendMsgToMainThread(MsgType.CONTROLLER_MSG, "自检完毕");

            Constants.ORDER = true;

            return;
        }
        else
        {
            OrderLoad nextOrder = this.getNextOrder();
            if (nextOrder != null)
            {
                nextOrder.doOrder(order);
            }
        }
    }
}
